package com.softeem.music_sys.controller;

import com.softeem.music_sys.comm.Result;
import com.softeem.music_sys.entity.Album;
import com.softeem.music_sys.service.AlbumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 专辑控制器
 */
@Tag(name = "专辑接口", description = "专辑相关操作:添加、查询、修改、删除等")
@RestController
@RequestMapping("/album")
public class AlbumController {
    
    @Autowired
    private AlbumService albumService;

    @Operation(summary = "添加专辑", description = "添加新专辑信息")
    @PostMapping
    public Result add(@RequestBody Album album) {
        return albumService.addAlbum(album);
    }

    @Operation(summary = "获取专辑信息", description = "根据ID获取专辑详细信息")
    @GetMapping("/{id}")
    public Result getAlbumById(@PathVariable Integer id) {
        return albumService.getAlbumById(id);
    }

    @Operation(summary = "更新专辑信息", description = "更新专辑信息")
    @PutMapping
    public Result update(@RequestBody Album album) {
        return albumService.updateAlbum(album);
    }

    @Operation(summary = "删除专辑", description = "根据ID删除专辑")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        return albumService.deleteAlbum(id);
    }

    @Operation(summary = "获取专辑列表", description = "分页获取专辑列表")
    @Parameters({
            @Parameter(name = "page", description = "页码"),
            @Parameter(name = "limit", description = "每页数量")
    })
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                      @RequestParam(defaultValue = "10") Integer limit) {
        return albumService.getAlbumList(page, limit);
    }

    @Operation(summary = "搜索专辑", description = "根据专辑名搜索")
    @GetMapping("/search")
    public Result search(@RequestParam String name,
                        @RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer limit) {
        return albumService.searchAlbumsController(name, page, limit);
    }

    @Operation(summary = "获取歌手的专辑", description = "根据歌手ID获取其所有专辑")
    @GetMapping("/singer/{singerId}")
    public Result getBySinger(@PathVariable Integer singerId,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit) {
        return albumService.getAlbumsBySingerController(singerId, page, limit);
    }

    @Operation(summary = "按发行公司获取专辑", description = "根据发行公司获取专辑列表")
    @GetMapping("/company")
    public Result getByCompany(@RequestParam String company,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer limit) {
        return albumService.getAlbumsByCompanyController(company, page, limit);
    }

    @Operation(summary = "修改专辑状态", description = "上架/下架专辑")
    @Parameters({
            @Parameter(name = "id", description = "专辑ID"),
            @Parameter(name = "status", description = "状态 1-上架 0-下架")
    })
    @PutMapping("/status/{id}")
    public Result updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        return albumService.updateStatusController(id, status);
    }
}